//
//  StaticData.cpp
//  beast_tamer
//
//  Created by bean on 13/2/6.
//  Copyright 2013年 __MyCompanyName__. All rights reserved.
//

#include "StaticData.h"
#include "XmlDataSheetCPP.h"

static const char* SKILL_NAME = "skill";
static const char* MONSTER_NAME = "monster";
static StaticData *s_sharedStaticData = NULL;
StaticData* StaticData::sharedStaticData(void)
{
    if (!s_sharedStaticData)
    {
        s_sharedStaticData = new StaticData();
    }
    return s_sharedStaticData;
}

StaticData::StaticData(void)
{
    
    XmlDataSheetCPP* xmlParser = new XmlDataSheetCPP("game_data");
    xmlParser->printAllSheetName();
    
    this->loadItem(xmlParser);
    this->loadMonster(xmlParser);
}

bool StaticData::init(void)
{
    return true;
}

StaticData::~StaticData(void)
{
    
}
/*
 <element name="id" type="integer" />
 <element name="name" type="string" />
 <element name="description" type="string" />
 <element name="race" type="string" />
 <element name="head equip" type="string" />
 <element name="left hand equip" type="string" />
 <element name="right hand equip" type="string" />
 <element name="atk" type="string" />
 <element name="def" type="string" />
 <element name="hp" type="string" />
 <element name="speed" type="string" />
 <element name="atk speed" type="string" />
 <element name="terrain" type="string" />
 <element name="weather" type="string" />
 <element name="probability" type="integer" />
 <element name="animation type" type="string" />
 <element name="act mode" type="string" />
 */
void StaticData::loadMonster(XmlDataSheetCPP *xmlParser)
{
    int colCount = xmlParser->getColumnCount(MONSTER_NAME);
    int rowCount = xmlParser->getRowCount(MONSTER_NAME);
    for (int i = 0; i < rowCount; i++) {
        
        m_monsterStruct[i].monsterId = atoi(xmlParser->getData(MONSTER_NAME, "id", i));
        m_monsterStruct[i].name = xmlParser->getData(MONSTER_NAME, "name", i);
        const char* race = xmlParser->getData(MONSTER_NAME, "race", i);
        m_monsterStruct[i].race = getRaceTypeWithRaceName(race);
        m_monsterStruct[i].head = xmlParser->getData(MONSTER_NAME, "head", i);
        m_monsterStruct[i].left = xmlParser->getData(MONSTER_NAME, "left", i);
        m_monsterStruct[i].right = xmlParser->getData(MONSTER_NAME, "right", i);
        m_monsterStruct[i].atk =atoi(xmlParser->getData(MONSTER_NAME, "atk", i));
        m_monsterStruct[i].def =atoi(xmlParser->getData(MONSTER_NAME, "def", i));

    }
}
Race getRaceTypeWithRaceName(const char* race)
{
    if (strcmp(race, "orc")) return RaceOrc;
    else if (strcmp(race, "dwraf")) return RaceDwarf;
    else return RaceElf;
}
void StaticData::loadItem(XmlDataSheetCPP* xmlParser)
{
    
    
    
}